package in.muton.edushare.pages.user;

import in.muton.edushare.processing.objects.UnivDataHandler;
import in.muton.edushare.url.EntityPageParams;
import in.muton.edushare.wicket.models.CayenneList;
import in.muton.panels.paginator.EntityListing;

import java.util.List;

import org.apache.wicket.PageParameters;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.vo.Departments;
import com.edushare.common.vo.Universities;

public class UserDept extends UserBase {

	public UserDept(PageParameters params) {
		super(params);
		cL = null;
		getDepartments(params);
		add(new EntityListing<Departments>("thumbList", cL, this));
	}

	@Override
	public String getActivePage() {
		return "UserDept";
	}

	@Override
	public String getPageTitle() {
		return getModel().getObject().getCompleteUserName()
				+ " | Departments | " + ApplicationConstants.APPLICATION_NAME;
	}

	public void getDepartments(PageParameters params) {
		String id = params.getString("1", "mine");
		WebMarkupContainer wmc1;
		if (id.compareTo("all") == 0) {
			cL = new CayenneList<Departments>(null);
			List<IModel<Universities>> ul = ud.getUniv().getObject();

			for (IModel<Universities> u : ul) {
				cL.add(new UnivDataHandler(u).getAllDept());
			}

			wmc1 = new WebMarkupContainer("tab1");
			wmc1.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItem"), " "));
			add(wmc1);
			wmc1.add(new BookmarkablePageLink<Void>("link", UserDept.class,
					EntityPageParams.getParams(getModel())));

			wmc1 = new WebMarkupContainer("tab2");
			wmc1.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItemSelected"), " "));
			wmc1.add(new BookmarkablePageLink<Void>("link", UserDept.class,
					EntityPageParams.getParams(getModel(), "all")));
			add(wmc1);
		} else {
			cL = ud.getAllDepts();
			wmc1 = new WebMarkupContainer("tab1");
			wmc1.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItemSelected"), " "));
			add(wmc1);
			wmc1.add(new BookmarkablePageLink<Void>("link", UserDept.class,
					EntityPageParams.getParams(getModel())));

			wmc1 = new WebMarkupContainer("tab2");
			wmc1.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItem"), " "));
			add(wmc1);
			wmc1.add(new BookmarkablePageLink<Void>("link", UserDept.class,
					EntityPageParams.getParams(getModel(), "all")));
		}
	}

	private CayenneList<Departments> cL = null;

	@Override
	public String getUserRole() {
		return " : Departments";
	}
}
